<template>
  <el-card shadow="never">
    <e-table
      ref="eTable"
      @getList="handleGetList"
      :tableData="tableData"
      :columns="columns"
      :loading="loading"
      :total="total"
    />
  </el-card>
</template>

<script>
import { getReportClinicRefundMonitor } from '@/api/reports'
export default {
  data() {
    return {
      total: 1,
      loading: false,
      tableData: [],
      columns: [],
      queryParam: {
        pageSize: 10,
        pageNo: 1
      }
    }
  },
  methods: {
    //columns 动态删减，根据form传递过来的数据
    async handleGetList(param = {}) {
      this.loading = true
      this.columns = [
        {
          label: '退费时间',
          prop: 'refund_time'
        },
        {
          label: '退费金额',
          prop: 'refund_cost'
        }
      ]
      this.queryParam = Object.assign(this.queryParam, param)

      if (this.queryParam.refundItemState) {
        this.columns.unshift(
          {
            label: '项目单价',
            prop: 'item_price'
          },
          {
            label: '项目数量',
            prop: 'item_qty'
          },
          {
            label: '退费项目',
            prop: 'refund_item'
          }
        )
      }

      if (this.queryParam.handlerState) {
        this.columns.unshift(
          {
            label: '操作员工号',
            prop: 'handler_code'
          },
          {
            label: '操作员工姓名',
            prop: 'handler_name'
          },
          {
            label: '发票号',
            prop: 'receipt_no'
          }
        )
      }
      if (this.queryParam.doctorState) {
        this.columns.unshift(
          {
            label: '医生工号',
            prop: 'his_doctor_code'
          },
          {
            label: '医生名称',
            prop: 'his_doctor_name'
          }
        )
      }
      if (this.queryParam.patientNameState) {
        this.columns.unshift(
          {
            label: '患者姓名',
            prop: 'patient_name'
          },
          {
            label: '病历号',
            prop: 'med_record_no'
          },
          {
            label: '患者电话',
            prop: 'phone'
          }
        )
      }

      if (this.queryParam.itemTypeState) {
        this.columns.unshift({
          label: '项目类别',
          prop: 'item_type'
        })
      }
      if (this.queryParam.hisDeptState) {
        this.columns.unshift(
          {
            label: '科室名称',
            prop: 'his_dept_name'
          },
          {
            label: '科室代码',
            prop: 'his_dept_code'
          }
        )
      }
      if (this.queryParam.dateState) {
        this.columns.unshift({
          label: '日期',
          prop: 'dt'
        })
      }
      const res = await getReportClinicRefundMonitor(this.queryParam)
      if (res && res.data.records.length > 0) {
        const {
          state,
          data: { records, total }
        } = res
        this.tableData = records
        this.total = total
      } else {
        this.tableData = []
        this.total = 1
      }
      this.loading = false
    }
  }
}
</script>
